//
//  CQTopView.swift
//  swift-weibo
//
//  Created by 陈乾 on 15/10/31.
//  Copyright © 2015年 陈乾. All rights reserved.
//

import UIKit


class CQTopView: UIView {
   /*
    ///友好显示名称
    var name: String?
    ///用户头像地址（中图），50×50像素
    var profile_image_url: String?
    /// verified_type -1:没有认证 0:认证用户 2,3,5: 企业认证，220: 达人
    var verified_type: Int = -1
    /// 会员等级 1-6
    var mbrank: Int = 0
    
    */
    
    ///微博数据模型
    var status: CQStatus? {
        didSet{
            //如果这个url有值就去网上加载数据
            if let image_url = status?.user?.profile_image_url {
             
                iconView.sd_setImageWithURL(NSURL(string: image_url))
            }
            
            //设置昵称
            nameLabel.text = status?.user?.name
            
            //设置发布时间
            timeLabel.text = status?.created_at
            
            //设置发布来源
            sourceLabel.text = status?.source
            
            //vip图标
            VipView.image = status?.user?.mbRank
            
            //认证图标
            verifiedView.image = status?.user?.verifiedTypeImage
            
        
        }
    
    }
    //MARK: - 初始化函数
    override init(frame: CGRect
        ) {
        super.init(frame: frame)
//     backgroundColor = UIColor.purpleColor()
            prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 准备UI
    func prepareUI() {
      //添加子控件
        self.addSubview(topSeparatorView)
        self.addSubview(iconView)
        self.addSubview(nameLabel)
        self.addSubview(timeLabel)
        self.addSubview(sourceLabel)
        self.addSubview(VipView)
        self.addSubview(verifiedView)
//        设置约束
        //设置顶部间隔view的约束
        topSeparatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSizeMake(UIScreen.screenWidth(), 10))
        //iconView
        
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topSeparatorView, size: CGSizeMake(35, 35), offset: CGPointMake(8, 8))
        
        //昵称
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPointMake(8, 0))
        //发布时间 
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPointMake(8, 0))
        //来源
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPointMake(8, 0))
        //vip 头像
        VipView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSizeMake(14, 14), offset: CGPointMake(8, 0))
        
        //认证
        verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSizeMake(17, 17), offset: CGPointMake(8.5, 8.5))
    
    }
    
    //MARK: -懒加载
    //顶部View上面的分割view
    private lazy var topSeparatorView: UIView = {
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.9, alpha: 0.9)
        return view
        }()
    
    ///iconView
    private lazy var iconView: UIImageView = UIImageView()
    
    ///昵称
    private lazy var nameLabel: UILabel = UILabel(fontSize: 15, color: UIColor.blackColor())
    
    ///发布时间
    private lazy var timeLabel: UILabel = UILabel(fontSize: 9, color: UIColor.orangeColor())
    
    ///来源
    private lazy var sourceLabel: UILabel = UILabel(fontSize: 9, color: UIColor.lightGrayColor())
    
    ///vip 头像
    private lazy var VipView: UIImageView = UIImageView()
    ///认证图标
    
    private lazy var verifiedView :UIImageView = UIImageView()
    
    
    
}
